#include "../include/FireworkCircleAndInBall.h"

#include <algorithm>
#include <iterator>

#include "../include/utilities.h"

void FireworkCircleAndInBall::initFireworkParticles() {
	
	std::uniform_int_distribution<> lengthDis(-1, 0);
	std::normal_distribution<float> speedDis(10, 5);
	std::uniform_real_distribution<float> radiusDis(-20, 20);
	std::uniform_int_distribution pointCountDis(-20, 20);
	
	float radius = 100 + radiusDis(m_gen);
	std::uniform_int_distribution circleCountDis(3, 20);
	uint8_t circleCount = circleCountDis(m_gen);
	float initSpeed = fabsf(20 + speedDis(m_gen));
	float lengthBomb = 2 + lengthDis(m_gen);
	
	std::vector<Vector3> speedList;
	for (int i = 0; i < circleCount; ++i) {
		Vector3 normal = getRandomNormal(-90, 90, 0, 360);
		std::vector<Vector3> circlePointPos = getNormalCirclePos(m_pos, radius, normal, 0, 360, 30);
		std::vector<Vector3> tmpSpeedList = getSpeedlistFromPoslist(m_pos, initSpeed, circlePointPos);
		std::copy_n(tmpSpeedList.begin(), tmpSpeedList.size(), std::back_inserter(speedList));
	}
	Color color = getRandomColor();
	addNewBombs(m_pos, speedList, color, lengthBomb);
	
	std::uniform_int_distribution<> alphaCountDis(10, 30);
	int alphaCountRandom = alphaCountDis(m_gen);
	std::uniform_int_distribution<> betaCountDis(10, 30);
	int betaCountRandom = betaCountDis(m_gen);
	float speedRatio = 0.7;
	float iterRatio = 0.4;
	while (isToDo(iterRatio)) {
		color = getRandomColor();
		initSpeed = initSpeed * speedRatio;
		speedList.clear();;
		std::vector<Vector3> ballPointPosList = getBallPos(m_pos, 1, alphaCountRandom, betaCountRandom);
		for (Vector3& ballPointPos : ballPointPosList) {
			Vector3 direction = Vector3Normalize(Vector3Subtract(ballPointPos, m_pos));
			Vector3 speed = Vector3Scale(direction, initSpeed);
			speedList.push_back(speed);
		}
		addNewBombs(m_pos, speedList, color, lengthBomb);
	}
}

